﻿using System;
using System.Data;
using DMS.Business.Modules.Statistics;
using System.Text;
using InfoSoftGlobal;

namespace DMS.Web.Modules.Statistics
{
    public partial class StatByDeptControl : System.Web.UI.UserControl
    {
        private int _chartWidth=400;
        public int ChartWidth
        {
            get
            {
                return _chartWidth;
            }
            set
            {
                _chartWidth = value;
            }
        }

        private int _chartHeigth = 400;
        public int ChartHeight
        {
            get
            {
                return _chartHeigth;
            }
            set
            {
                _chartHeigth = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Stat();
            }
        }

        private void Stat()
        {
            string condition = "";//string.Format(" and InitialTime >= '{0}'", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1));

            DataSet ds = new StatService().StatByDeptAndType(condition);

            DrawChart(ds);
        }

        /// <summary>
        ///  画图
        /// </summary>
        private void DrawChart(DataSet ds)
        {
            //分类、分部门统计数量
            StringBuilder sb = new StringBuilder();
            StringBuilder dw = new StringBuilder();
            StringBuilder gth = new StringBuilder();
            StringBuilder gr = new StringBuilder();
            sb.Append("<chart caption='参保户数分类统计' baseFontSize='15' showAboutMenuItem='0' shownames='1' imageSave='0'"
                      + " imageSaveDialogFontColor ='cfbbfc'>");//imageSaveURL='FusionChartsSave.jsp'
            sb.Append("<categories>");
            foreach (DataRow row in ds.Tables[0].Rows)
            {   
                sb.Append(string.Format("<category label='{0}' />",row["deptname"]));
                dw.Append(string.Format("<set value='{0}' />",row["dwQuantity"]));
                gth.Append(string.Format("<set value='{0}' />",row["gthQuantity"]));
                gr.Append(string.Format("<set value='{0}' />",row["grQuantity"]));
            }
            sb.Append("</categories>");

            sb.Append(string.Format("<dataset seriesName='单位' color='0070CB' showValues='1'>{0}</dataset>",dw));
            sb.Append(string.Format("<dataset seriesName='个体户' color='FBC400' showValues='1'>{0}</dataset>",gth));
            sb.Append(string.Format("<dataset seriesName='个人' color='8BBA00' showValues='1'>{0}</dataset>",gr));
            sb.Append("</chart>");
            //Create the chart - Column 3D Chart with data from Data/Data.xml 
            //RenderChart方法可在源码包中查找
            litChart.Text = FusionCharts.RenderChart("../../FusionCharts/MSColumn3D.swf", "", sb.ToString(), "myFirst",
                                                     "100%",ChartHeight.ToString(), false, true); 
        }
    }
}